package com.itheima.framework.view;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: Implementing springmvc
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-05 11:23
 **/
public class PrintViewHandler implements ViewHandler {
    @Override
    public void print(HttpServletRequest request,
                      HttpServletResponse resp,
                      Object result) {
        try {
            System.out.println("json格式....." + result);
            resp.setContentType("application/json;charset=utf-8");
            String res = JSON.toJSONString(result);
            resp.getWriter().write(res);
            resp.getWriter().close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
    }
}
